﻿/*****************************************************************//**
 * @file    FITKGraphObjectGeoPartFeaturePreview.h
 * @brief   Geometry graph object for previewing feature faces.
 *
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2025-01-14
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTGEOPARTFEATUREPREVIEW_H__
#define __FITKGRAPHOBJECTGEOPARTFEATUREPREVIEW_H__

#include "FITKGraphObjectModelBase.h"

#include "FITKVTKGraphAdaptorAPI.h"

#include <QVector>

// Forward declaration
class vtkDataSet;
class vtkUnstructuredGrid;

class FITKGraphActor;

namespace AbaqusData
{
    class FITKAbaqusPart;
}

namespace Exchange
{
    /**
     * @brief   Geometry graph object for previewing feature faces.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2025-01-14
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectGeoPartFeaturePreview : public FITKGraphObject3D
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectGeoPartFeaturePreview, FITKGraphObject3D);
        FITKCLASS(Exchange, FITKGraphObjectGeoPartFeaturePreview);

    public:
        /**
         * @brief   Constructor.
         * @param   caseData: The case data
         * @param   part: The part data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        FITKGraphObjectGeoPartFeaturePreview(AbaqusData::FITKDataCase* caseData, AbaqusData::FITKAbaqusPart* part);

        /**
         * @brief   Destructor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        ~FITKGraphObjectGeoPartFeaturePreview();

        /**
         * @brief   Update all graph actors.[override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        void update(bool forceUpdate = false) override;

        /**
         * @brief   Enable or disable transparent.
         * @param   isOn: Enable or disable
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        void setTransparent(bool isOn);

        /**
         * @brief   Set if the graph object can be picked.[override]
         * @param   isPickable: Pickable
         * @param   dim: The dimision of the pickable object( -1 means the whole graph object )[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        void setPickable(bool isPickable, int dim = -1) override;

        /**
         * @brief   Get the faces' ids by the given face topo id.
         * @param   faceId: The face topo id
         * @return  The face topo id list
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        QVector<int> getFaceIdsByFaceId(int faceId);

        /**
         * @brief   Get the command id by the given vtk cell id.
         * @param   cellId: The vtk cell id
         * @return  The command id
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        int getCommandIdByCellId(int cellId);

        /**
         * @brief   Get the vtk cell id by the given face topo id.
         * @param   cellId: The vtk cell id
         * @return  The vtk cell id list
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        QVector<int> getCellIdByFaceId(int faceId);

        /**
         * @brief   Get the face topo id by the given vtk cell id.
         * @param   cellId: The vtk cell id
         * @return  The face topo id
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        int getFaceIdByCellId(int cellId);

        /**
         * @brief   Get the edge cell ids by the given face topo id.
         * @param   faceId: The face topo id
         * @return  The edge cell ids
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        QVector<int> getEdgeCellIdsByFaceId(int faceId);

        /**
         * @brief   Get the vtkDataSet by the given dimension.
         * @param   dim: The dim of the data set( 1: Edge, 2: Face )
         * @return  The vtkDataSet
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        vtkDataSet* getMesh(int dim);

    private:
        /**
         * @brief   Initialize.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        void init();

        /**
         * @brief   Generate the vtk data.
         * @return  Is OK
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        bool generateDataSet();

        /**
         * @brief   Generate the shape actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        void generateGraph();

        /**
         * @brief   Clear all data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        void clearData();

    private:
        /**
         * @brief   The actor for edges.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        FITKGraphActor* m_fActorEdge{ nullptr };

        /**
         * @brief   The actor for faces.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        FITKGraphActor* m_fActorFace{ nullptr };

        /**
         * @brief   The grid data for feature faces'edges( for visualization ).
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        vtkUnstructuredGrid* m_ugridEdge{ nullptr };

        /**
         * @brief   The grid data for feature faces.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        vtkUnstructuredGrid* m_ugridFace{ nullptr };

        /**
         * @brief   The dict for vtk cell id and command id.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        QVector<int> m_cellIdCmdIdMap;

        /**
         * @brief   The dict for vtk cell id and face topo id.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        QVector<int> m_cellIdFaceIdMap;

        /**
         * @brief   The dict for face topo id and vtk cell ids.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        QHash<int, QVector<int>> m_faceIdCellIdsMap;

        /**
         * @brief   The dict for face topo id and its face's group ids.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        QHash<int, QVector<int>> m_faceIdFeatFaceIdsMap;

        /**
         * @brief   The dict for face topo id and the its edges' cell ids.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        QHash<int, QVector<int>> m_faceIdEdgeCellIdsMap;

        /**
         * @brief   The last shape state.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2025-01-14
         */
        QVariant m_shapeState = QVariant();

    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTGEOPARTFEATUREPREVIEW_H__
